package cn.itsource.basic.exception;

import cn.itsource.basic.util.AjaxResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice //可以对所有加了requestMapping的方法进行增强：异常处理，全局属性绑定。。。。
public class GlobalException {

    @ExceptionHandler(value = CustomException.class)//捕获处理指定的异常
    public AjaxResult CustomExceptionHandler(CustomException e){
        e.printStackTrace();
        return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    public AjaxResult ExceptionHandler(Exception e){
        e.printStackTrace();
        return AjaxResult.me().setSuccess(false).setMessage("服务器繁忙，请稍后重试!");
    }

}
